package com.crack.nga2.span;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.crack.nga2.R;

import java.io.IOException;
import java.io.InputStream;

/**
 * 表情获取
 * Created by Administrator on 2016/1/4.
 */
public class EmotionGetterImpl implements SpanUtil.EmotionGetter {
    private Context context;

    public EmotionGetterImpl(Context context) {
        this.context = context;
    }

    @Override
    public Drawable getDrawable(String source) {
        try {
            InputStream is = context.getAssets().open("emotions/" + source + ".png");
            Drawable d = Drawable.createFromStream(is, source);
            d.setBounds(0, 0, d.getIntrinsicWidth() * 4, d.getIntrinsicHeight() * 4);
            is.close();
            return d;
        } catch (IOException e) {
            e.printStackTrace();
            return context.getResources().getDrawable(R.drawable.error_tag);
        }
    }
}
